﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Microsoft.Expression.Interactivity.Core;
using System.Windows.Threading;
using System.Windows.Browser;

namespace ScrumBoard.Views
{
  public partial class Welcome : Page
  {
    bool isFirstTime = true;
    public Welcome()
    {
      InitializeComponent();
    }

    // Executes when the user navigates to this page.
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
      ExtendedVisualStateManager.GoToElementState((App.Current.RootVisual as MasterView).LayoutRoot, "FullScreen", !isFirstTime);

      ExtendedVisualStateManager.GoToElementState(LayoutRoot, "Welcome1", false);
      isFirstTime = false;
    }

    private void btnLogin_Click(object sender, RoutedEventArgs e)
    {
      (DataContext as MainVM).CurrentUser = tbxUserName.Text;
      var t = new DispatcherTimer();
      t.Interval = TimeSpan.FromMilliseconds(300);
      t.Start();
      t.Tick += (s, arg) =>
      {
        NavigationService.Navigate(new Uri("/Board", UriKind.Relative));
        t.Stop();
      };

      ExtendedVisualStateManager.GoToElementState((App.Current.RootVisual as MasterView).LayoutRoot, "Normal", !isFirstTime);
    }

    private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
    {
      try
      {
        HtmlPage.PopupWindow(new Uri("http://onlinescrumboard.codeplex.com/", UriKind.Absolute), "_blank", new HtmlPopupWindowOptions());
      }
      catch { }
    }

    private void tbxUserName_TextChanged(object sender, TextChangedEventArgs e)
    {
      btnLogin.IsEnabled = !string.IsNullOrWhiteSpace(tbxUserName.Text);
    }

  }
}
